import socket
from netpkg import *
from testdata import *
from ioloop import *

class TestConnection(object):
    def __init__(self, testmanager, idx, ip, port, io_loop):
        self._idx = idx
        self._testmanager = testmanager
        self._ip = ip
        self._port = port
        self._ioloop = io_loop
        self._sfd = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
        self._sfd.setblocking(0)
        self._stream = IOStream(self._sfd)
        try:
            self._sfd.connect((ip, int(port))
        except socket.error as error:
            if error.errno != errno.EINPROGRESS:
                print error.strerror
                raise
        self._connecting = True
        self._ioloop.add_handler(self._sfd, self.on_connected, self._ioloop.WRITE)

    def on_connected(self):
        
        now = time.time()
        self._birth = now
        for testitem in testdata.DATA:
           self._ioloop.add_timeout(now + testitem[0], self.on_timeout)

    def on_timeout(self):
        

    def on_rsp_header(self):
        pass

    def on_rsp_body(self):
        pass

class TestManager(object):
    def __init__(self, peer_num = 1):
        self.pkg_generator = PkgGenerator()
        self.test_data = testdata.DATA
        self.peer_num = peer_num
        self.ioloop = ioloop.IOLoop.instance()

    def setup(self):
        for 

    def _connect(self):
        pass


